import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mall/constant/app_colors.dart';
import 'package:mall/gen/r.dart';
import 'package:mall/utils/image_component/image_component.dart';

class AgreementWidget extends StatelessWidget {
  const AgreementWidget({
    super.key,
    required this.hasReadProtocol,
  });

  final RxBool hasReadProtocol;

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        InkWell(
          onTap: () {
            hasReadProtocol.value = !hasReadProtocol.value;
          },
          child: Container(
            width: 30,
            height: 30,
            child: Center(
              child: Obx(() => ImageComponent(
                    hasReadProtocol.value ? R.image.selectTrue.path : R.image.selectFalse.path,
                    size: 14,
                  )),
            ),
          ),
        ),
        SizedBox(
          width: 0,
        ),
        Expanded(
          child: Text.rich(
            TextSpan(
              text: '我已阅读并同意',
              style: const TextStyle(
                color: AppColors.C_666666,
                fontSize: 12,
              ),
              children: [
                _buildTextSpan('《用户协议》', const Color(0xFF4C94FF), onTapFun: () {
                  // UserService.gotoUserXieYi();
                }),
                _buildTextSpan('《隐私政策》', const Color(0xFF4C94FF), onTapFun: () {
                  // UserService.gotoYinSiXieYi();
                }),
              ],
            ),
          ),
        ),
      ],
    );
  }

  TextSpan _buildTextSpan(String text, Color color, {double? fontSize = 12, Function? onTapFun}) {
    return TextSpan(
        text: text,
        style: TextStyle(color: color, fontSize: fontSize),
        recognizer: TapGestureRecognizer()
          ..onTap = () {
            if (null != onTapFun) {
              onTapFun();
            }
          });
  }
}
